import * as types from './type';
import {fromJS} from "immutable";

const defaultData = fromJS({
    account: '',
    password: '',
    SignInfo: {
        account: '',
        password: '',
        SurePassword: '',
        phone: '',
        email: '',
        SMSCode: '',
        mailCode: '',
    }
})

//eslint-disable-next-line
export default (state = defaultData, action) => {
    let newVal = action.value;
    if (newVal !== undefined) {
        switch (action.type) {
            case types.LOGIN_INPUT_ACCOUNT:
                return state.set('account', newVal);
            case types.LOGIN_INPUT_PASSWORD:
                return state.set('password', newVal);
            case types.SIGN_INPUT_ACCOUNT:
                return state.setIn(['SignInfo', 'account'], newVal);
            case types.SIGN_INPUT_PASSWORD:
                return state.setIn(['SignInfo', 'password'], newVal);
            case types.SIGN_INPUT_SURE_PASSWORD:
                return state.setIn(['SignInfo', 'SurePassword'], newVal);
            case types.SIGN_INPUT_PHONE:
                return state.setIn(['SignInfo', 'phone'], newVal);
            case types.SIGN_INPUT_EMAIL:
                return state.setIn(['SignInfo', 'email'], newVal);
            case types.SIGN_INPUT_SMS_CODE:
                return state.setIn(['SignInfo', 'SMSCode'], newVal);
            case types.SIGN_INPUT_MAIL_CODE:
                return state.setIn(['SignInfo', 'mailCode'], newVal);
            default:
                return state;
        }
    }
    return state;
}
